import 'package:flutter/material.dart';
import 'package:netflix_social/theme/app_theme.dart';

class CategoryCard extends StatelessWidget {
  final String category;
  final VoidCallback onTap;

  const CategoryCard({
    Key? key,
    required this.category,
    required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 根据不同类别设置不同的背景图片
    String imageUrl = _getImageForCategory(category);
    
    return GestureDetector(
      onTap: onTap,
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          image: DecorationImage(
            image: NetworkImage(imageUrl),
            fit: BoxFit.cover,
            colorFilter: ColorFilter.mode(
              Colors.black.withOpacity(0.6),
              BlendMode.darken,
            ),
          ),
        ),
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(8),
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                Colors.transparent,
                AppTheme.netflixRed.withOpacity(0.7),
              ],
              stops: const [0.7, 1.0],
            ),
          ),
          child: Center(
            child: Text(
              category,
              style: const TextStyle(
                color: Colors.white,
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ),
    );
  }

  String _getImageForCategory(String category) {
    // 根据类别返回对应的图片URL
    switch (category.toLowerCase()) {
      case '电影':
        return 'https://images.unsplash.com/photo-1536440136628-849c177e76a1?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '电视剧':
        return 'https://images.unsplash.com/photo-1522869635100-9f4c5e86aa37?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '动漫':
        return 'https://images.unsplash.com/photo-1533075377664-f5c0cbc5a91c?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '综艺':
        return 'https://images.unsplash.com/photo-1514525253161-7a46d19cd819?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '纪录片':
        return 'https://images.unsplash.com/photo-1507041957456-9c397ce39c97?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '儿童':
        return 'https://images.unsplash.com/photo-1489710437720-ebb67ec84dd2?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '喜剧':
        return 'https://images.unsplash.com/photo-1527224857830-43a7acc85260?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '动作':
        return 'https://images.unsplash.com/photo-1519389950473-47ba0277781c?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '爱情':
        return 'https://images.unsplash.com/photo-1518599807935-37015b9cefcb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '惊悚':
        return 'https://images.unsplash.com/photo-1506354666786-959d6d497f1a?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '科幻':
        return 'https://images.unsplash.com/photo-1518770660439-4636190af475?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      case '剧情':
        return 'https://images.unsplash.com/photo-1485846234645-a62644f84728?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
      default:
        return 'https://images.unsplash.com/photo-1489599849927-2ee91cede3ba?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60';
    }
  }
}
